//
//  PopOverPresentationController.swift
//  WeiBo
//
//  Created by 江潘 on 15/6/29.
//  Copyright © 2015年 江潘. All rights reserved.
//

import UIKit

class PopOverPresentationController: UIPresentationController {
    
    var presentVcFrame = CGRectZero
    
    lazy var coverView:UIView = {
        let v = UIView()
        let tap = UITapGestureRecognizer(target: self, action: "close")
        v.addGestureRecognizer(tap)
        v.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
        return v
    }()
    
    func close(){
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
        
    override func containerViewWillLayoutSubviews() {

        super.containerViewWillLayoutSubviews()
        
        coverView.frame = containerView!.bounds
        
        containerView?.insertSubview(coverView, atIndex: 0)
        
        presentedView()!.frame = presentVcFrame
    }
}
